#include <stdio.h>

typedef unsigned fb;

int f2i(fb f){
    unsigned sign, exp, frac, last_bit;
    int i;
    sign = f >> 31;
    exp = (f >> 23) & 0xff;
    frac = f & 0x7fffff;
    if (exp == 158 && frac == 0 && sign == 1)
        i = 0x80000000;
    else if (exp > 157 || exp == 0xff)
        i = 0x80000000;
    else if (exp < 126)
        i = 0;
    else{
        exp -= 127;
        frac |= 0x800000;
        if (exp > 23){
            exp -= 23;
            frac <<= exp;
        }else if (exp < 23){
            exp = 23 - exp;
            frac >>= exp;
        }
        if (sign == 1)
            i = (~frac) + 1;
        else
            i = frac;
    }
    return i;
}
void main(){
    float f;
    unsigned i;
    int j, k;
    
    for (i = 0x3fbfff70U; i <= 0xffffffffU; i++)
    {
        f = *(float *)&i;
        j = (int)f;
        k = f2i(i);
        printf("原值：%f \t 函数运算：%d \t 机器运算：%d\n", f, k, j);
    }
}
